//
// Created by mi on 2024/5/6.
//
#include <functional>
#include <memory>
#include <string>
#include <iostream>
#include <utility>

using  namespace  std;

 class Channel
{
 public:
    typedef std::function<void(std::string)> EventCallback;
    EventCallback writeCallback_;
    void setWriteCallback(EventCallback cb)
    {// writeCallback_ = std::move(cb);
        //
        //
        writeCallback_ = std::move(cb);
    }
    void show(){
        writeCallback_("hello world");
    }
};

class Connector{
public:
    Channel channel_;
    void preHandle(){
        channel_.setWriteCallback(std::bind(&Connector::handleWrite, this,std::placeholders::_1));
    }
    void handleWrite(std::string str){
        std::cout << str << std::endl;
    };
};
//bind的绑定有多种，有普通函数，也有类里面的方法。
int main(){
    Connector connector;
    connector.preHandle();
    connector.channel_.show();
    return 0;
}